#!/usr/bin/env bash

# Pass url to release file to download, something like:
# $ ./update-bootstrap https://github.com/twbs/bootstrap/releases/download/v3.3.5/bootstrap-3.3.5-dist.zip

cd lib
rm -rf bootstrap
curl -L $1 > bootstrap.zip
unzip bootstrap.zip -d .
rm bootstrap.zip
mv bootstrap* bootstrap
cd bootstrap/css

# replace relative urls to fonts with absolute ones
sed 's/..\/fonts/\/lib\/bootstrap\/fonts/g' bootstrap.css > bootstrap-tmp1.css
sed 's/..\/fonts/\/lib\/bootstrap\/fonts/g' bootstrap.min.css > bootstrap.min-tmp1.css

# remove sourceMappingURL to prevent it loading the sourcemap
sed 's/# sourceMappingURL=/ /g' bootstrap-tmp1.css > bootstrap-tmp2.css
sed 's/# sourceMappingURL=/ /g' bootstrap.min-tmp1.css > bootstrap.min-tmp2.css

# rename adapted css files
mv bootstrap-tmp2.css bootstrap.css
mv bootstrap.min-tmp2.css bootstrap.min.css

# cleanup
rm bootstrap-tmp1.css
rm bootstrap.min-tmp1.css
